from typing import Optional, List, Any
from pydantic import BaseModel, EmailStr, Field

from app.schemas.base import BaseSchema


class RegisterForm(BaseModel):
    """注册表单"""
    tenantId: str
    username: str
    password: str
    confirmPassword: Optional[str] = None
    code: Optional[str] = None
    uuid: Optional[str] = None
    userType: Optional[str] = None


class LoginData(BaseModel):
    """登录请求"""
    tenantId: Optional[str] = None
    username: Optional[str] = None
    password: Optional[str] = None
    rememberMe: Optional[bool] = None
    socialCode: Optional[str] = None
    socialState: Optional[str] = None
    source: Optional[str] = None
    code: Optional[str] = None
    uuid: Optional[str] = None
    clientId: str
    grantType: str


class LoginResult(BaseModel):
    """登录响应 - Plus-UI兼容"""
    access_token: str
    expires_in: Optional[int] = None


class VerifyCodeResult(BaseModel):
    """验证码返回"""
    captchaEnabled: bool
    uuid: Optional[str] = None
    img: Optional[str] = None


class TenantVO(BaseModel):
    """租户选项 - Plus-UI兼容"""
    companyName: str
    domain: Optional[str] = None
    tenantId: str


class TenantInfo(BaseModel):
    """租户信息"""
    tenantEnabled: bool
    voList: List[TenantVO]


class ChangePasswordRequest(BaseModel):
    """修改密码请求 - Plus-UI兼容"""
    oldPassword: str = Field(..., min_length=6, max_length=100, description="原密码")
    newPassword: str = Field(..., min_length=6, max_length=100, description="新密码")
    confirmPassword: str = Field(..., min_length=6, max_length=100, description="确认密码")


class UserInfo(BaseSchema):
    """用户信息 - Plus-UI兼容"""
    userId: int
    userName: str
    nickName: Optional[str] = None
    email: Optional[str] = None
    phonenumber: Optional[str] = None
    avatar: Optional[int] = None
    sex: Optional[str] = None
    status: str
    admin: bool
    tenantId: str
    deptId: Optional[int] = None
    roles: List[str] = []
    permissions: List[str] = []